package com.example.shixunandjavagotoyangchen.Eternity.LoginActivity;

import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.modelviewpresenter.View.BasterActivity;
import com.example.shixunandjavagotoyangchen.BoosYang.BoosYangActivity;
import com.example.shixunandjavagotoyangchen.BuildConfig;
import com.example.shixunandjavagotoyangchen.Eternity.ReisterActivity.ReisterActivity;
import com.example.shixunandjavagotoyangchen.R;

@Route(path = "/yemian/login")
public class LoginActivity extends BasterActivity implements LoginContion.loginview {

    private android.widget.TextView LoginReister;
    private android.widget.TextView LoginShengming;
    private Button LoginDenglu;
    private android.widget.EditText loginPhone;
    private android.widget.EditText loginPassword;
    LoginPresenter presenter;


    @Override
    public int BandLayout() {
        return R.layout.activity_login;
    }

    @Override
    public void initView() {

        LoginReister = (TextView) findViewById(R.id.Login_reister);
        LoginShengming = (TextView) findViewById(R.id.Login_shengming);
        LoginDenglu = (Button) findViewById(R.id.Login_denglu);
        loginPhone = (EditText) findViewById(R.id.login_phone);
        loginPassword = (EditText) findViewById(R.id.login_password);

        presenter = new LoginPresenter(this,new LoginModel());

    }

    @Override
    public void initDate() {

        LoginReister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build("/login/reister")
                        .withString("login","注册")
                        .navigation();
                finish();
            }
        });

        LoginDenglu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!TextUtils.isEmpty(loginPhone.getText().toString()) && !TextUtils.isEmpty(loginPassword.getText().toString())) {
                    presenter.dologin(loginPhone.getText().toString(),loginPassword.getText().toString());
                } else {
                    Log.i("" + BuildConfig.BUILD_TYPE, "请完善资料");
                }

            }
        });


        LoginShengming.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ARouter.getInstance()
                        .build("/login/loginshengming")
                        .withString("login","登录用户协议")
                        .navigation();
            }
        });


    }


    @Override
    public void getloginview(LoginBean loginBean) {
        if (loginBean.getErrorCode()==0){
            ARouter.getInstance()
                    .build("/login/main")
                    .withString("login","登录成功")
                    .navigation();
            Log.i("" + BuildConfig.BUILD_TYPE, "登录成功"+loginBean.getErrorMsg());
        }else {
            Log.i("" + BuildConfig.BUILD_TYPE, "登录失败"+loginBean.getErrorMsg());

        }
    }
}
